//
//  AutomaticCell.m
//  ClassManager
//
//  Created by mac on 2018/1/8.
//  Copyright © 2018年 GZX. All rights reserved.
//

#import "AutomaticCell.h"
#import "AutomaticModel.h"
#import "Masonry.h"


@implementation AutomaticCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        _imageViews = [NSMutableArray array];
        self.autoLabel = [[UILabel alloc]init];
        self.autoLabel.font = [UIFont systemFontOfSize:15.];
        self.autoLabel.textColor = [UIColor colorWithWhite:0.3 alpha:1];
        self.
        self.autoLabel.numberOfLines = 0;
        [self.contentView addSubview:self.autoLabel];
            [self.autoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.contentView).offset(10);
                make.left.mas_equalTo(self.contentView).offset(10);
                make.right.mas_equalTo(self.contentView).offset(-10);
                make.bottom.equalTo(self.contentView).offset(-10).priorityLow();
            }];

        for (NSInteger i = 0; i < 9; i ++ ) {
            UIImageView *imageView = [[UIImageView alloc]init];
            imageView.backgroundColor = [UIColor redColor];
            [self.contentView addSubview:imageView];
            [_imageViews addObject:imageView];
        }

    }
    return self;
}

-(void)ReloadData:(id)sender{

    AutomaticModel *model = sender;

    self.autoLabel.text = model.name;

    if (model.isOpen == YES) {
        self.autoLabel.numberOfLines = 0;
    }
    else{
        self.autoLabel.numberOfLines = 3;
    }

    NSInteger count = model.num;
    float imageWidth = (kScreenWidth - 40)/3;


    for (int i=0; i< 9; i++) {
        [_imageViews[i] setHidden:YES];
        [_imageViews[i] mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.width.and.height.mas_equalTo(imageWidth);
            make.left.mas_equalTo(self.contentView).offset(10+(imageWidth+10)*(i%3));
            make.top.mas_equalTo(self.autoLabel.mas_bottom).offset(10+(imageWidth+10)*(i/3));
        }];
    }
    if (count>0) {
        for (int i=0; i<count; i++) {
            [_imageViews[i] setHidden:NO];
            if (i==count-1) {
                [_imageViews[i] mas_makeConstraints:^(MASConstraintMaker *make){
                    make.bottom.equalTo(self.contentView).offset(-10).priorityHigh();
                }];
            }
        }
    }

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
